package com.lenovo.smarttraffic.ui.activity.stage8;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lenovo.smarttraffic.R;
import com.lenovo.smarttraffic.ui.activity.BaseActivity;
import com.lenovo.smarttraffic.ui.activity.Item1Activity;

import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.Locale;

public class NewsActivity extends BaseActivity {

    public static WeakReference<Drawable> drawable;

    private boolean hasPic = false;
    private int type = 0;
    private String title = "";
    private String time = "";
    private String info = "";

    private TextView mTitle;
    private TextView mTime;
    private TextView mNewsTv;
    private ImageView mPic;

    @Override
    protected int getLayout() {
        return R.layout.activity_news;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            hasPic = (boolean) bundle.get("hasPic");
            type = (int) bundle.get("type");
            title = (String) bundle.get("title");
            time = (String) bundle.get("time");
            info = (String) bundle.get("info");
        } else finish();

        initToolBar(this, title);
        initView();

        mTitle.setText("分类：" + Item1Activity.cates[type]);

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
        SimpleDateFormat format2 = new SimpleDateFormat("yyyy年MM月dd日 HH点mm分", Locale.CHINA);

        try {
            mTime.setText(format2.format(format.parse(time)));
        } catch (Exception e) {
            e.printStackTrace();
        }

        mNewsTv.setText("\t\t\t\t" + info);

        if (hasPic) {
            mPic.setVisibility(View.VISIBLE);

            if (drawable != null && drawable.get() != null) {
                mPic.setImageDrawable(drawable.get());
            }
        }

    }

    private void initView() {
        mTitle = findViewById(R.id.title);
        mTime = findViewById(R.id.time);
        mNewsTv = findViewById(R.id.news_tv);
        mPic = findViewById(R.id.pic);
    }
}
